/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.test_finder;

import picounit.Marker;
import picounit.Test;
import picounit.TestFilter;
import picounit.features.class_finder.ClassFinder;
import picounit.features.class_finder.FindAction;
import picounit.features.coverage_measuring.SuiteDecorator;
import picounit.features.failures_first.ProblemTracker;
import picounit.features.failures_first.StatusPersister;
import picounit.features.test_factory.TestFactory;
import picounit.features.test_instantiator.TestInstantiator;
import previous.picounit.Is;
import previous.picounit.Should;
import previous.picounit.TestCase;
import previous.picounit.Verify;
import junit.framework.TestSuite;

public class DirectoryScanningTestFinderTest extends TestCase {
	private final ClassFinder classFinder = injectCollaborator();
	private final TestInstantiator testInstantiator = injectCollaborator();
	private final TestFilter testFilter = injectCollaborator();
	private final ClassLoader classLoader = injectCollaborator();
	private final StatusPersister statusPersister = injectCollaborator();
	private final SuiteDecorator suiteDecorator = injectCollaborator();
	private final TestFactory testFactory = injectCollaborator();
	private final ProblemTracker problemTracker = injectCollaborator();

	private final ObjectReloader objectReloader = injectCollaborator();
	
	private final Marker marker = injectCollaborator();
	private final Marker reloadedMarker = injectCollaborator();
	
	private final DirectoryScanningTestFinder testFinder =
		new DirectoryScanningTestFinder(statusPersister, classFinder, suiteDecorator, testFactory,
			testInstantiator, classLoader, problemTracker, objectReloader);

	class StartingClass {}
	class TestExample implements Test {}
	class NonTestClass {}

	@SuppressWarnings("unchecked")
	public void shouldUseClassFinderToFindTests(Should should, Is is, Verify verify) {
		shouldCall:
			statusPersister.inform(StartingClass.class, testFilter);

		shouldCall:
			classFinder.findClasses(StartingClass.class, is.instanceOf(FindAction.class));
	
		should.call(objectReloader.reload(marker))
			.andReturn(reloadedMarker);

		TestSuite decoratedSuite = new TestSuite();

		should.call(suiteDecorator.decorate(is.instanceOf(TestSuite.class)))
			.andReturn(decoratedSuite);

		should.expectAboveWhenTheFollowingOccurs();

		verify.that(testFinder.findTests("name", StartingClass.class, marker, testFilter))
			.isTheSameAs(decoratedSuite);
	}
}
